package com.xinqi.modules.chat.sysmessage.controller;

import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.modules.chat.sysmessage.service.SysRongYunUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 融云用户用于系统发送消息
 * @author: yyzhen
 * @date: 2023/03/23
 */
@Validated
@RestController
@RequestMapping("/sysrongyun/user")
@RequiredArgsConstructor
public class SysRongUserController {

    private final SysRongYunUserService sysRongYunUserService;

    /**
     * 添加系统融云用户
     * @author dzy
     */
    @PostMapping("/add")
    public R insert() {
        if (sysRongYunUserService.save()) {
            return R.ok(MessageUtils.message("chat.favorite.tag.add.success"));
        }
        return R.fail(MessageUtils.message("chat.favorite.tag.add.fail"));
    }

    /**
     * 批量添加系统融云用户
     * @author dzy
     */
    @PostMapping("/add-batch")
    public R addBatch(Integer number) {
        if (sysRongYunUserService.saveBatch(number)) {
            return R.ok(MessageUtils.message("chat.favorite.tag.add.success"));
        }
        return R.fail(MessageUtils.message("chat.favorite.tag.add.fail"));
    }

    /**
     * 更新系统用户到Redis
     * @author dzy
     */
    @PostMapping("/refresh")
    public R refresh() {
        sysRongYunUserService.refreshRedis();
        return R.ok(MessageUtils.message("chat.favorite.tag.add.success"));
    }

}
